package com.shuqi.controller;

import java.util.Stack;

import android.content.Context;

import com.shuqi.common.utils.Log4an;

/**
 * 总控制中心
 * 
 * @author zhangpeng
 * 
 */
public class MainController {
    /** 启动软件页控制ID */
    public static final int CONTROLLER_ID_LOADING = 1;
    /** 首页推荐ID */
    public static final int CONTROLLER_ID_RECOMMEND = 2;

    /** 限免界面ID */
    public static final int CONTROLLER_ID_FREE = 3;

    /** 首页排行ID */
    public static final int CONTROLLER_ID_RANKLIST = 4;
    /** 搜索界面ID */
    public static final int CONTROLLER_ID_BOOKSEARCH = 5;
    /** 首页分类ID */
    public static final int CONTROLLER_ID_RORT = 6;
    /** 曾经浏览 */
    public static final int CONTROLLER_ID_BROWSINGHISTORY = 7;
    /** 购买历史 */
    public static final int CONTROLLER_ID_PURCHASEHISTORY = 8;
    /** 书籍详情页控制ID */
    public static final int CONTROLLER_ID_BOOKDETAILS = 12;
    /** 书籍详情：封面页控制ID */
    public static final int CONTROLLER_ID_BOOKCOVER = 13;
    /** 书籍详情：目录页控制ID */
    public static final int CONTROLLER_ID_BOOKCATALOG = 14;

    /** 排行详情 */
    public static final int CONTROLLER_ID_RANKLISTDETAILS = 9;

    /** 专题详情 */
    public static final int CONTROLLER_ID_PROJECTDETAILS = 10;
    /** 更多推荐 */
    public static final int CONTROLLER_ID_MORERECOMMEND = 11;

    /** 搜索结果界面ID */
    public static final int CONTROLLER_ID_BOOKSEARCHRESULT = 12;

    /** 书架 */
    public static final int CONTROLLER_ID_BOOKSHELF = 15;

    /** 书架 */
    public static final int CONTROLLER_ID_SORTDETSILDHOT = 20;

    /** 分类详情 -最火 */
    public static final int CONTROLLER_ID_SORTDETAILSHOT = 25;

    /** 分类详情 -完结 */
    public static final int CONTROLLER_ID_SORTDETAILSEND = 30;

    /** 分类详情 -最新 */
    public static final int CONTROLLER_ID_SORTDETAILSNEW = 35;

    /** 设置 */
    public static final int CONTROLLER_ID_USERSETTINGACTIVITY = 36;

    /** 推广墙 */
    public static final int CONTROLLER_ID_OFFERWALLACTIVITY = 37;

    /** 推广墙详情页 */
    public static final int CONTROLLER_ID_OFFERWALL_ITEM_ACTIVITY = 38;

    /** 书签列表 */
    public static final int CONTROLLER_ID_LabelList = 40;

    /** 我的收藏 */
    public static final int CONTROLLER_ID_MY_FAVORIT = 41;

    /** 作者列表 */
    public static final int CONTROLLER_ID_AuthorlList = 410;

    /** 我的资料修改 */
    public static final int CONTROLLER_ID_MYACCOUNTDATA = 411;

    /** 密码修改 */
    public static final int CONTROLLER_ID_PASSWORDMODIFY = 412;

    /** 邮箱、手机注册 */
    public static final int CONTROLLER_ID_MAIL_MOBILE_REGISTER = 413;

    /** 账号绑定 */
    public static final int ACCOUNT_ID_BIND = 42;

    /** 意见反馈 */
    public static final int CONTROLLER_ID_FEEDBACK = 45;

    /** 意见反馈 */
    public static final int CONTROLLER_ID_RECHARGES = 50;


    /** 找回密码 */
    public static final int CONTROLLER_ID_FINDPASSWORD = 60;

    /** 绑定手机号 */
    public static final int CONTROLLER_ID_ACCOUNT_BINDPHONE = 70;

    /** 账号页 */
    public static final int CONTROLLER_ID_ACCOUNT = 71;

    /** 购买记录 */
    public static final int CONTROLLER_ID_PAYHISTORY = 47;

    /** 购入章节 */
    public static final int CONTROLLER_ID_PAYCHAPTERHISTORY = 48;

    /** 登录 */
    public static final int CONTROLLER_ID_LOGIN_ACCOUNT = 72;
    /** 男频 */
    public static final int CONTROLLER_ID_LOGIN_MAN = 100;
    /** 女频 */
    public static final int CONTROLLER_ID_LOGIN_WOMAN = 101;

    /** 搜索界面 */
    public static final int CONTROLLER_ID_SEARCHALL = 105;

    private static MainController mainManager = null;
    private String Tag = "MainManager";

    private MainController() {

    }

    public static MainController getMainManagerInstance() {
        if (mainManager == null) {
            mainManager = new MainController();
        }
        return mainManager;
    }

    /**
     * 保存所有manager
     */
    private volatile Stack<ControllerBase> managerStack = new Stack<ControllerBase>();

    /**
     * manager
     */
    public ControllerBase createController(int controllerID, Context context) {
        ControllerBase manager = null;
        switch (controllerID) {
            case CONTROLLER_ID_ACCOUNT:
                manager = new AccountController(context);
                break;
            case CONTROLLER_ID_BOOKCOVER:
                manager = new BookCoverController(context);
                break;
            case CONTROLLER_ID_BOOKCATALOG:
                manager = new BookCatalogController(context);
                break;

            case CONTROLLER_ID_BOOKSEARCH:
                manager = new BookSearchRankController(context);
                break;

            case CONTROLLER_ID_PURCHASEHISTORY:
                manager = new PurchaseHistoryController(context);
                break;
            case CONTROLLER_ID_BOOKSEARCHRESULT:
                manager = new BookSearchResultController(context);
                break;
            case CONTROLLER_ID_PROJECTDETAILS:
                manager = new ProjectDetailsController(context);
                break;
            case CONTROLLER_ID_MORERECOMMEND:
                manager = new MoreRecommengController(context);
                break;
            case CONTROLLER_ID_RECOMMEND:
                manager = new RecommendController(context);
                break;
            case CONTROLLER_ID_BOOKSHELF:
                manager = new BookShelfController(context);
                break;
            case CONTROLLER_ID_USERSETTINGACTIVITY:
                manager = new UserSettingController(context);
                break;
            case CONTROLLER_ID_MY_FAVORIT:
                manager = new MyFavoritController(context);
                break;
            case CONTROLLER_ID_LabelList:
                manager = new LabelListController(context);
                break;
            case CONTROLLER_ID_AuthorlList:
                manager = new AuthorListController(context);
                break;
            case CONTROLLER_ID_MYACCOUNTDATA:
                manager = new AccountDataModifyController(context);
                break;
            case CONTROLLER_ID_PASSWORDMODIFY:
                manager = new PasswordModifyController(context);
                break;
            case CONTROLLER_ID_MAIL_MOBILE_REGISTER:
                manager = new AccountRegisterController(context);
                break;
            case CONTROLLER_ID_OFFERWALLACTIVITY:
                manager = new OfferWallController(context);
                break;
            case CONTROLLER_ID_OFFERWALL_ITEM_ACTIVITY:
                manager = new OfferWallItemController(context);
                break;
            case ACCOUNT_ID_BIND:
                manager = new AcountBindVerifyCodeController(context);
                break;
            case CONTROLLER_ID_FEEDBACK:
                manager = new FeedBackController(context);
                break;
            case CONTROLLER_ID_RECHARGES:
                manager = new RechargesController(context);
                break;
            case CONTROLLER_ID_FINDPASSWORD:
                manager = new FindPasswordController(context);
                break;
            case CONTROLLER_ID_ACCOUNT_BINDPHONE:
                manager = new AccountBindController(context);
                break;
            case CONTROLLER_ID_PAYHISTORY:
                manager = new PayHistoryController(context);
                break;
            case CONTROLLER_ID_PAYCHAPTERHISTORY:
                manager = new PayChapterHistoryController(context);
                break;
            case CONTROLLER_ID_LOGIN_ACCOUNT:
                manager = new LoginAcountController(context);
                break;
            case CONTROLLER_ID_SEARCHALL:
                manager = new BookSearchRecoomendController(context);
            default:
                break;
        }
        // managerStack.add(manager);
        return manager;

    }

    /**
     * 删除对应的manager
     */
    public void delCurManager(ControllerBase manager) {
        if (manager == null) {
            Log4an.e(Tag, "manager is null");
            return;
        }
        for (ControllerBase curManager : managerStack) {
            if (curManager.getClass().equals(manager)) {
                managerStack.remove(curManager);
                curManager = null;
            }
        }
        Log4an.d(Tag, "manager num is : " + managerStack.size());
    }

    /**
     * 删除所有的manager
     */
    public void delAllManager() {
        for (ControllerBase curManager : managerStack) {
            managerStack.remove(curManager);
            curManager = null;
        }
        Log4an.d(Tag, "manager num is : " + managerStack.size());
    }

    public void exitShuQi() {

    }
}
